# import time
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# driver = webdriver.Chrome()
# # driver.get("https://y.qq.com/portal/pop_login.html/")
# driver.get("https://y.qq.com/")
# driver.implicitly_wait(15)
# driver.maximize_window()
# driver.find_element(By.ID,"switcher_plogin").click()
# web_qr_login =driver.find_element(By.ID,"web_qr_login")
# driver.switch_to.frame(web_qr_login)



# crmeb
import time
import uuid
from selenium import webdriver
from Wanglinlin.CRMEB.lcotor import *
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class CRMEB:
    uuid_ = str(uuid.uuid4()).split('-')[0]
    def __init__(self,driver,url):
        self.driver = driver
        self.driver = webdriver.Chrome()
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        self.driver.maximize_window()
        time.sleep(3)
    def login(self,user:str,password:str):
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located(user_ele))[0].send_keys(user)
        time.sleep(3)
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located(password_ele))[1].send_keys(password)
        time.sleep(2)
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located(login_ele)).click()
    def add_group_user(self,name):
        self.name = name
        time.sleep(3)
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located(user_icon_ele))[1].click()
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located(user_group_ele)).click()
        time.sleep(3)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(add_group_ele)).click()
        time.sleep(5)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(add_groupname_ele))[2].send_keys(self.name+str(self.uuid_))
        time.sleep(5)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(click_groupname_ele))[2].click()
        time.sleep(3)
    def check_name(self):
        time.sleep(2)
        text = self.driver.find_element(By.XPATH,f"//*[text()='{self.name}{str(self.uuid_)}']").text
        assert text == self.name + str(self.uuid_)
        time.sleep(15)
    def del_groupname(self):
        time.sleep(2)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(del_groupname_ele))[-1].click()
        time.sleep(2)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(click_del_groupname_ele))[2].click()
        time.sleep(2)
    def add_user_title(self,name):
        self.name = name
        time.sleep(3)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_icon_ele))[1].click()
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(user_title_ele)).click()
        time.sleep(3)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(add_user_title_ele)).click()
        time.sleep(5)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(add_titlename_ele))[2].send_keys(self.name+str(self.uuid_))
        time.sleep(5)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(click_titlename_ele))[2].click()
        time.sleep(3)


if __name__ == '__main__':
    driver = webdriver.Chrome()
    url = "http://8.148.229.201:8899/admin/"
    d_crmeb = CRMEB(driver, url)
    d_crmeb.login('admin', '123456')
    d_crmeb.add_group_user("琳琳")
    d_crmeb.check_name()
    d_crmeb.del_groupname()
    # d_crmeb.add_user_title("黄哥")

